package com.hatch.utils
{
	import flash.text.TextField;		import flash.display.DisplayObject;	

	import com.hatch.utils.StringUtils;
		public class DisplayUtils
	{
		public function DisplayUtils()
		{
		}
		
		public static function reparent(mc:DisplayObject, level:uint = 0):void
		{
			if(!mc.parent) return;
			if(!mc.parent.contains(mc)) return; //return if child is not on stage
			if(!mc.parent.getChildIndex(mc) == mc.parent.numChildren - 1 - level) return; //return if child is already top child
			try
			{
				mc.parent.setChildIndex(mc, mc.parent.numChildren-1 - level);
			}
			catch(e:Error)
			{
				trace("REPARENTING ERROR : " + e.message);
			}
		}
		
		public static function autoSizeTextHeight(tf:TextField, maxHeight:Number):void
		{
			var l:int = tf.text.length;
			var s:String = tf.text;
			while(tf.textHeight > maxHeight)
				tf.htmlText = StringUtils.truncate(s, --l);
		}
	}
}